{% extends 'TopxiaWebBundle::layout.html.twig' %}
{% block title %} 订单确认 - {{ parent() }}{% endblock %}
{% set script_controller = 'order/create' %}

{% block esBar %}{% endblock %}

{% block content %}
<div class="order-pay">
  <div class="order-nav hidden-xs clearfix">
    <div class="on">确认订单<b></b></div>
    <div><span></span>订单支付<b></b></div>
    <div><span></span>订单完成</div>
  </div>
  <div class="es-section">
    <div class="section-header"><h1>订单确认</h1></div>
    <div class="order-pay-body">
      <form id="order-create-form" method="post" action="{{path('order_create')}}">
        <input type="password" style="display:none">
        {% if order|default(null) %}
        <input type="hidden" name="orderId" value="{{order.id}}"/>
        {% endif %}
        <input type="hidden" role="cash-rate" value="{{cashRate|default(null)}}"
        data-price-type = "{{priceType|default('RMB')}}"/>
        <input type="hidden" name="targetType" value="{{targetType}}"/>
        <input type="hidden" name="maxRate" value="{{maxRate|default(100)}}"/>
        <input type="hidden" name="targetId" value="{{targetId}}"/>
        <input type="hidden" id="totalPrice" name="totalPrice" value="{{totalPrice}}"/>
         <input type="hidden" id="cm" name="cm" value=""/>
       	
	{# 曹乾 #}
	{% if targetType=='course' %}
       {% if course.type==' offline ' %}
		  <input type="hidden"  name="teacherIds" value="{{ teacherIds }}"/>
	   {% endif %}
		<input type="hidden"  name="offline" value="{{ course.type }}"/>
		<input type="hidden" name="discount" value="{{ course.discount }}">
		
		<input type="hidden" name="discountId" value="{{ course.discountId }}">

	   {% if course['tags'] %}
		<input type="hidden" name="category" value="{{ course['tags'][0] }}">
	   {% else %}
		<input type="hidden" name="category" value="">

    {% endif %}


	{% endif %}
	
        <input type="hidden" name="shouldPayMoney" id="shouldPayMoney"  value=""/>
        <input type="hidden" name="sms_code" value=""/>
		<!--翟红利优惠券-->
		<input type="hidden" id="promo" name="promo" value=""/>
        <input type="hidden" id="mz" name="mz" value=""/>
		<!--翟红利优惠券-->
        <input type="hidden" name="mobile" data-role="mobile" value="{{ verifiedMobile }}"/>
        <input type="hidden" name="_csrf_token" value="{{ csrf_token('site') }}">
        <div class="order-detail-bg" >
		
        {% if targetType == "course" and course|default(null) %}
          {% include 'TopxiaWebBundle:Order:order-course.html.twig' %}
        {% endif %}
		
        {% if targetType == "vip" %}
          {% include 'TopxiaWebBundle:Order:vip.html.twig' %}
        {% endif %}
		
        {% if targetType == "classroom" %}
          {% include 'TopxiaWebBundle:Order:classroom.html.twig' %}
        {% endif %}
		
        </div>

        {% if isice == '0' %}
		{% if (is_plugin_installed("Coupon") and setting('coupon.enabled') and (targetType in ['course','vip','classroom']) and showCoupon|default(false)) or setting('coin.coin_enabled') %}
        <div class="order-detail-bg" {% if targetId in ['249','250','251'] %}style="display:none;"{% endif %}>
		<!--使用优惠券-->
		{% if setting('coin.coin_enabled') %}
        	 {% include 'TopxiaWebBundle:Order:order-item-coupon.html.twig' %}
        {% endif %}
		  <!--使用优惠券-->
        {% if is_plugin_installed("Coupon") and setting('coupon.enabled') and (targetType in ['course','vip','classroom']) and showCoupon|default(false) %}
          {% if version_compare(plugin_version('Coupon'),'1.3.3','>') %}
          {{ render(controller('TopxiaWebBundle:Card:useableCoupons', {targetType: targetType, targetId: targetId, totalPrice: totalPrice,priceType:priceType|default('RMB') })) }}
          {% else %}
            {% include 'TopxiaWebBundle:Order:order-item-coupon.html.twig' %}
          {% endif %}
        {% endif %}

        {% if is_plugin_installed("Coupon") and setting('coupon.enabled') and (targetType in ['course','vip','classroom']) and showCoupon|default(false) and setting('coin.coin_enabled') %}
        <div class="divider-line"></div>
        {% endif %}
		
        {% if setting('coin.coin_enabled') %}
		
        	{% include 'TopxiaWebBundle:Order:order-item-coin.html.twig' %}
			
			
        {% endif %}
		{% if targetType=='course' %}
		 <!--            如果是面授课程显示填写个人信息-->
     
             {% if course.type=='offline' %}

                {% include 'TopxiaWebBundle:Order:order-item-offline.html.twig' %}
              {% endif %}
            {% endif %}  
		  <!--使用优惠券-->
        </div>
        {% endif %}
        {% endif %}

        <div class="form-group">
          <div class="total-price">
            应付金额：
            {% if priceType|default('RMB') == "Coin" %}
              <span role="pay-coin">0</span> {{setting("coin.coin_name")}} ÷ 汇率({{cashRate|default(1)}}) = <span class="pay-rmb">￥</span> <span role="pay-rmb" class="pay-rmb"></span> 元
            {% else %}
              <span class="pay-rmb">￥</span><span role="pay-rmb" class="pay-rmb"></span> 
            {% endif %}
          </div>
        </div>
        <div class="form-group text-right">
          <a 
            {% if targetType == "course" and course|default(null) %}
              href="{{ path('course_show', {id:course.id}) }}" 
            {% elseif targetType == "vip" %}
              href="{{ path('vip_renew') }}"
            {% elseif targetType == "classroom" %}
              href="{{ path('classroom_show', {id:classroom.id}) }}"
            {% endif %}
            class="btn btn-link" style="">取消</a>
          {% if ((setting('cloud_sms.sms_enabled')|default('')) == '1') and ((setting('cloud_sms.sms_user_pay')|default('')) == 'on') %} 
 {% if isice %}
 <a class="btn btn-primary" id="js-order-create-sms-btn" data-toggle="modal" data-target="#modal" data-url="{{path('order_pay_sms_verification')}}"onclick="return submi_ice()" >提交订单</a>
 {% else %}
            <a class="btn btn-primary" id="js-order-create-sms-btn" data-toggle="modal" data-target="#modal" data-url="{{path('order_pay_sms_verification')}}" >提交订单</a>
   {% endif %}          
          {% else %}
            {% if targetType=='course' %}
			{% if course.type != 'offline' %}
                 {% if course.isice %}
					<button class="btn btn-primary" id="order-create-btn" type="submit" onclick="return submi_ice()" >提交订单</button>
				 {% else %}
					<button class="btn btn-primary" id="order-create-btn" type="submit" onclick="return submi()" >提交订单</button>
				 {% endif %}
                
            {% else %}
				 <button class="btn btn-primary" id="order-create-btn" type="submit" onclick="return check()">生成订单</button> 
            {% endif %}
            {% else %}
             <button class="btn btn-primary" id="order-create-btn" type="submit" onclick="return submi()" >提交订单</button>
			
            {% endif %}
		 {% endif %}
        </div>
      </form>
    </div>
  </div>
</div>
</div>

<script>
	function submi(){
		var coin=$('[role="coinNum"]').val();
		var payPassword=$('#payPassword').val();
		
		if(Number(coin)>0){
			if(payPassword==""){
				alert("支付密码不为能为空");
				return false;
			}
		}
		
	}
	function submi_ice(){
		$('#order-create-form').attr('action',$('#order-create-form').attr('action') + '?isice=1');
	}
 function check()  
  {  
      var name = document.getElementById("name").value; 
      var tel = document.getElementById("tel").value; 
      var address = document.getElementById("address").value; 
      //var note = document.getElementById("note").value; 
       
      if(name==''){  
          document.getElementById("name").style.border = "1px solid red";
          $(".name").text('姓名不能为空');
         return false;  
      }else{
          $(".name").text(''); 
          document.getElementById("name").style.border = "1px solid #e1e1e1";
          return true;
      } 
     
      if(tel==''){
        document.getElementById("tel").style.border = "1px solid red";
          $(".tel").text('电话不能为空');
         
         return false;  
      }else{
         $(".tel").text(''); 
            document.getElementById("tel").style.border = "1px solid #e1e1e1";
          return true;
      } 
      if(address==''){
       document.getElementById("address").style.border = "1px solid red";
          $(".address").text('地址不能为空'); 
         return false;  
      }else{
          document.getElementById("address").style.border = "1px solid #e1e1e1";
           return true;
      }
 }  
</script>

{% endblock %}